home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / ALL96.LZH / t0226 / text0039.txt < prev    next >
Encoding:
Text File  |  1996-03-07  |  7.7 KB  |  307 lines

  1. It seems that not everybody has MIME complaint mailers here.
  2. So I'll send the BMCL specs once as a normal mail.
  3.  
  4. For future refernce: Please get yourselves MIME-mailers so I
  5. or anybody else dosent need to send doubly again.
  6.  
  7. -- 
  8. Elias Martenson                    elias@omicron.se
  9.  
  10.  
  11.  
  12. ------------- cut here ---------------------
  13. Bad Mood Control Language specifications
  14. (C) 1996  Elias Martenson
  15.  
  16.  
  17.  
  18. **** TABLE OF CONTENTS
  19.  
  20. - ABSTRACT
  21. - LANGUAGE SPECIFICATION
  22.     - INTRODUCTION
  23.     - VARIABLE DECLARATIONS
  24.     - METHOD DECLARATIONS
  25.     - EVENT METHOD DECLARATIONS
  26.     - EXECUTION CONTEXT
  27.     - ACTION PRIMITIVES
  28. - IMPLEMENTATION
  29.     - INTRODUCTION
  30.     - COMPILATION
  31.  
  32.  
  33.         
  34.  
  35. ****    ABSTRACT
  36.  
  37. There has been lot of discussion on the Bad Mood mailing list
  38. about how the AI should be done in Bad Mood. This document
  39. describes my suggestion to how this could be solved.
  40. This is only the first draft and should not be taken as a
  41. definitive solution.
  42.  
  43. This document contains the specifications of a programming
  44. language currently called BMCL (Bad Mood Control Language)
  45. and can be used not only to control the monsters AI but
  46. also to control other game events, like keys and other
  47. puzzles.
  48.  
  49. This document also attepmts to make a suggestion about
  50. how the actual code implementation will be
  51. made (see: IMPLEMENTATION).
  52.  
  53.  
  54. ****    LANGUAGE SPECIFICATION
  55.  
  56. INTRODUCTION
  57.  
  58. In order to make the language efficient, we need a way to
  59. make the BMCL code run as little a possible, while still
  60. being able to control much of the game from it. The solution
  61. used is to design the language as an event driven language,
  62. which means that the BMCL code is only run when it needs to.
  63.  
  64. BMCL defines a generic entity called an Object. An object can
  65. be either a monster, a key, a powerup of some kind or
  66. bascially anything else. In this specification I will be
  67. focousing on the "Monster" type object beacuse monster
  68. control is the primary use for BMCL, at least in the
  69. first stage.
  70.  
  71. A "#" character in the imput file denotes a comment
  72. and causes the rest of the input line to be ignored.
  73.  
  74. An object definition looks like this:
  75.  
  76.     <object type> <object name> {
  77.         <object definitions>
  78.     }
  79.  
  80. The <object type> for a monster is "monster", so in order to
  81. define the monster type "guard" the definition would look
  82. something like this:
  83.  
  84.     monster guard {
  85.         <object definitions>
  86.     }
  87.  
  88. The <object definitions> is a list of methods and declarations.
  89. Each declaration can be either of: a variable declaration,
  90. a method or an event method.
  91.  
  92.  
  93. VARIABLE DECLARATIONS
  94.  
  95. A variable declaration looks like this:
  96.  
  97.     var <name> [,<name> ...] : <type> ;
  98.  
  99. Example: in order to declare a integer variable called "foo"
  100. for use inside the object:
  101.  
  102.     var foo: integer;
  103.  
  104. To declare the two variables "size" and "lenght" in one command:
  105.  
  106.     var size, lenght: integer;
  107.  
  108.  
  109. METHOD DECLARATIONS
  110.  
  111. A method is bascially a function or a procedure for use inside
  112. an object. A method is declared like this:
  113.  
  114.     function <name> : <function block>
  115.  
  116. The <function block> is the piece of code attached to the function
  117. <name>. Here is an example of a method:
  118.  
  119.     function turn_and_run: {
  120.         turn(180);    # make a full turn
  121.         forward(0);    # run forward until hitting
  122.                 # an obstacle
  123.     }
  124.  
  125.  
  126. EVENT METHOD DECLARATIONS
  127.  
  128. An event method is basically a normal method with the difference
  129. that is is called by the game engine at certain points (if it
  130. has beed declared).
  131.  
  132. An event method looks exactly like this:
  133.  
  134.     event <name> [<context>] : <function block>
  135.  
  136. The available event methods is not defined
  137. in this document but here are some examples:
  138.  
  139. init        Called once when the monster is created
  140. playerhit    Called whenever hit by a player
  141. monsterhit    Called whenever hit by another monster
  142. hitplayer    Called successfully hit a player
  143. hitmonster    Called when hitting another monster
  144. moveobstruct    Called when walking into a wall
  145.  
  146. Here is an example event method declaration for a monster
  147. that, when hit by a player, runs away until hitting a wall
  148. or other obstruction.
  149.  
  150.     event playerhit: {
  151.         turn_and_run();
  152.     }
  153.     event moveobstruct: {
  154.         stop();
  155.     }
  156.  
  157. In a complex design, one event method is not enough because
  158. it would conflict with our goal to avoid as much BMCL code
  159. execution as possible. For example, the definition for the
  160. turn_and_run method would have to look like this if it
  161. were to be used in a complex AI design:
  162.  
  163.     var is_escaping: integer;
  164.     function turn_and_run: {
  165.         is_escaping = 1;
  166.         turn(180);
  167.         forward(0);
  168.     }
  169.     event init: {
  170.         is_escaping = 0;
  171.     }
  172.     event playerhit: {
  173.         turn_and_run();
  174.     }
  175.     event hitplayer: {
  176.         if( is_escaping != 1 ) {
  177.             ... do something ...
  178.         }
  179.     }
  180.     event moveobstruct: {
  181.         if( is_escaping == 1 ) {
  182.             stop();
  183.             is_escaping = 0;
  184.         }
  185.     }
  186.  
  187.  
  188. EXECUTION CONTEXTS
  189.  
  190. As we can see, code is executed in the hitplayer event method
  191. just because we implemented a turn_and_run method. This is
  192. clearly not acceptable.
  193.  
  194. To cope with this the concept of an "execution context" has
  195. been designed.
  196. A piece of code can be run in an specific context and is then
  197. only affected by certain event methods.
  198. Here is an example of the turn_and_run method when implemeted
  199. using execution contexts:
  200.  
  201.     function turn_and_run: {
  202.         context *escaping {
  203.             turn(180);
  204.             forward(0);
  205.         }
  206.     }
  207.     event moveobstruct escaping: {
  208.         stop();
  209.     }
  210.  
  211. The asterisk in the "context *escaping" line means that the
  212. default methods should not be called while the monster is
  213. escaping.
  214.  
  215.  
  216. ACTION PRIMITIVES
  217.  
  218. An action primitive is a built-in method that instructs
  219. the monster to initiate a action. Actions include running,
  220. turning around and firing the weapon.
  221.  
  222. When an action primitive is called, the action is actually
  223. not performed, but the action is simply started. For example,
  224. the turn(180) call used in the previous example initiates
  225. the turn, which mean that the following forward(0) call
  226. causes the monster to actually run and rotate at the same
  227. time. If one wants to make the monster turn first and
  228. then run away the code would look like this:
  229.  
  230.     function turn_and_run: {
  231.         context *escaping {
  232.             turn(180);
  233.             wait(endturn);
  234.             forward(0);
  235.         }
  236.     }
  237.     event moveobstruct escaping: {
  238.         stop();
  239.     }
  240.  
  241. The "wait" function returns control to the game until the
  242. certain event is called. The "end<action>" events are
  243. events that are called whenever an action primitive
  244. has finished.
  245.  
  246.  
  247. ****    IMPLEMENTATION
  248.  
  249. INTRODUCTION
  250.  
  251. This section discusses the implementation of BMCL into the
  252. game. The first priority while designing this interface
  253. has been to minimize the actual code execution outside
  254. the games control. Still it will be possible for a BMCL
  255. programmer to create code that cause the game to
  256. hang, for example using an infinite loop.
  257.  
  258.  
  259. COMPILATION
  260.  
  261. The BMCL compiler will generate a singe 68030 source file
  262. as output. The file will declare a data structure for each
  263. object declared in the BMCL input file. The top level
  264. structure is a list of objects and looks like this:
  265.  
  266.     bmcl_toplevel:
  267.             dc.l    name,object
  268.             ...
  269.             dc.l    0,0
  270.  
  271. <name> is a pointer to a zero terminated string containing
  272. the name of the object and <object> is a pointer to the
  273. corresponding object definition. The list of objects
  274. is terminated by two NULL pointers.
  275.  
  276. An object looks like this:
  277.  
  278.     object:
  279.             dc.l    0        ; init
  280.             dc.l    0        ; playerhit
  281.             dc.l    foo        ; hitplayer
  282.             ...
  283.  
  284. That is, a list of the available event methods. Each entry
  285. is a pointer to the actual method or 0 if it isn't used.
  286.  
  287. The generated assembler will automatically modify this
  288. structure in case the "context" keyword is used. This
  289. means that the only thing needed to control a monster
  290. will be to read the monster structure for each monster
  291. to be updated and call the appropriate event functions
  292. to let the BMCL program update this information.
  293.  
  294. Here is an example of how the game code for the enemy hit
  295. detection may look like:
  296.  
  297.     ; the monster structure is assumed to be
  298.     ; available in a6, the pointer to the
  299.     ; event method list in (a6,0) and the
  300.     ; energy level in (a6,4)
  301.         checkplayerhit
  302.         beq    not_hit
  303.         subq.l    #1,(a6,4)
  304.         jsr    ([a6,0])
  305.     not_hit:
  306.  
  307.